<!DOCTYPE html>
<html>
	<head>
		<title>个人页面</title>
		<meta charset="utf-8"/>
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
		<link rel="stylesheet" href="/css/reset.css"/>
		<link rel="stylesheet" href="/css/userProfiles.css"/>
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script src="/js/common.js"></script>
		<script>
			$(function () {
			    //设置用户信息渲染标志
				var userData;
				//获取资源路径上的用户id
				var params = getParams();
                if (params.id) {//如果有id,发送Ajax请求获取用户的所有信息
                    var currentPage = 1;//当前页,默认首页为1
                    var pages;//存储总页数的容器
                    var travelData = [];//存储分页数据的容器
                    var loading = false;//标志,用来解决尾页多次触发查询的问题
                    //抽取分页查询
                    function query() {
                        //如果正在查询,就结束
                        if (loading) {
                            return;
                        }
                        //不在查询就查询,并修改标志为正在查询
                        loading = true;
                        //获取所有已发布游记数据
                        $.get("/users/"+params.id+"/travels",{currentPage:currentPage},function (data) {
                            console.log(data);
                            //获取单个用户数据,保存进容器中
                            if (!userData) {
                                $.each(data.list,function (index,ele) {
                                    //console.log(ele);
                                    userData=ele.author;
                                })
                            }
                            //将用户信息进行渲染
                            $(".userContainer").renderValues(userData);
                            //设置用户背景
                            $(".bg").css("background-image","url("+userData.coverImgUrl+")");

                            $.merge(travelData,data.list);//将每次查询的分页数据合并
                            var json = {list:travelData};//将数据封装成有list属性的对象
                            pages = data.pages;//获取总分页数
                            //对页面游记的分页信息进行数据渲染
                            $(".travelsContainer").renderValues(json,{
                                getUrl:function (item,value) {//参数1:获取贴有 render-fun="getUrl"属性的元素;参数2:可获取的参数
                                    var url = $(item).data("href");
                                    $(item).attr("href",url+value);//将id拼接在资源名后
                                }
							});
                            currentPage++;
                            //执行完查询之后,修改标志为不查询
                            loading = false;
                        })
                    }
                    //查询首页
                    query();
                    //给屏幕绑定滑动事件
                    $(window).scroll(function () {
                        //屏幕滚动触发分页查询(当屏幕的总高度加上溢出的总长度大于等于查询过来页面的长度时)
                        if ($(window).height() + $(document).scrollTop() >= $(document).height()) {
                            if (currentPage <= pages) {
                                query();//第二次查询
                            }else {
                                //提醒,没有更多数据了
                                $(document).dialog({
                                    type: 'notice',
                                    infoText: '没有更多数据了',
                                    autoClose: 1500,
                                    position: 'bottom'  // center: 居中; bottom: 底部
                                });
                            }
                        }
                    })
                }
            })
		</script>
	</head>
	<body>
		<div class="container bg">
			<a href="javascript:window.history.go(-1)" class="my-arrow">
				<span><i class="fa fa-chevron-left fa-2x"></i></span>
			</a>
			<div class="container">
				<div class="info userContainer">
					<img class="rounded-circle" width="17%" render-src="headImgUrl">
					<p class="name" render-html="nickName"></p>
					<p render-html="sign"></p>

					<div class="row num">
						<div class="col-2 border border-left-0 border-top-0 border-bottom-0">
							<div>
								<span >1</span>
							</div>
							<div>
								<span>关注</span>
							</div>
						</div>
						<div class="col-2">
							<div>
								<span>0</span>
									</div>
							<div>
								<span>粉丝</span>
							</div>
						</div>
						<div class="col">
							<button class="btn btn-outline-light ibtn" id="letterBtn">私信</button>
							<button class="btn btn-success ibtn" id="followBtn">关注</button>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="tabs">
			<ul class="nav nav-pills nav-justified  border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
				<li class="nav-item">
					<a class="nav-link active" id="travels-tab" data-toggle="pill" href="#travels">
						TA的游记[<span>1</span>]
					</a>
				</li>
				<li class="nav-item">
					<a class="nav-link " id="comments-tab" data-toggle="pill" href="#comments">
						TA的点评[<span>1</span>]
					</a>
				</li>
				<li class="nav-item">
					<a class="nav-link" id="pills-contact-tab" data-toggle="pill" href="#pills-contact">
						TA的旅行单[<span>0</span>]
					</a>
				</li>
			</ul>
			<div class="travelsContainer tab-content" id="pills-tabContent">
				<div class="tab-pane fade show active" id="travels" render-loop="list">
						<dl class="list">
							<dd>
								<a data-href="travelContent.html?id=" render-fun="getUrl" render-key="list.id">
									<img  render-src="list.coverUrl">
									<p><span class="title" render-html="list.title"></span>
										<span class="span-right">
						 				<span>0</span> <i class="fa fa-thumbs-o-up"></i></span><br>
									</p>
								</a>
								<hr>
							</dd>
						</dl>
				</div>

				<div class="comment tab-pane fade " id="comments">
				
					<div><div class="row">
							<div class="col-2 comment-head">
								<img  class="rounded-circle" src="/upload/7e854d1d-a7be-4360-8943-8771d18ee0e3.jpg">
							</div>
							<div class="col">
								<span class="comment-star" ><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-o"></i><i class="fa fa-star-o"></i></span>

								<span class="comment-date" >2018-07-11</span>
								<div class="comment-content">
									<a href="strategyComment.html"  data-id="4">
										<p >骑了个单车到沙面，春风把从上下九和宝华路带来的燥热吹散。沙面临江，下午的时光让这富有异国风情的公园显得更加宁静惬意，哪怕...</p>
									</a>
								</div>
								<ul class="comment-img"><li>
										<img  src="/upload/63bb765d-5dff-44f8-b7f1-cb338b9b9f95.jpeg">
									</li><li>
										<img  src="/upload/7d437f8d-a476-465c-bd84-e93a03d8efd5.jpeg">
									</li></ul>

								<div class="comment-link">
									<a href="strategyCatalogs.html" data-id="2">
										<img  src="/upload/e5e8a1a7-b127-4145-9fd0-a94e29f752ba.jpeg"> <span >广州攻略</span>
										<i class="fa fa-angle-right fa-2x"></i>
									</a>
								</div>

							</div>
						</div></div>

				</div>
				<div class="tab-pane fade" id="pills-contact">.3333..</div>
			</div>
		</div>
</body>
</html>